/**
 * 
 */
var pageii =null;

function selpatient(){
	pageii = layer.open({
		title : "选择用户",
		type : 2,
		area : [ "1000px", "80%" ],
		content : rootPath + '/patient/list.shtml?flag=true',
		btn: ['确定','关闭'],
        yes: function(index,layero){
        	var data = window["layui-layer-iframe" + index].getseldata();
        	var patient = data[0];
        	$("#patient_id").val(patient.id);
        	$("#patient_number").val(patient.patient_number);
        	$("#patient_name").val(patient.patient_name);
        	$("#patient_sex").val(patient.patient_sex);
        	$("#patient_age").val(patient.patient_age);
        	$("#patient_phone").val(patient.patient_phone);
        	$("#patient_address").val(patient.patient_address);
        	layer.close(index);
        } 
	});
}

function savepatient(){
	var patient_id = $("#patient_id").val();
	var patient_name = $("#patient_name").val();
	var patient_sex = $("#patient_sex").val();
	var patient_age = $("#patient_age").val();
	var patient_phone = $("#patient_phone").val();
	var patient_address = $("#patient_address").val();
	if(patient_name==null||patient_name==""||patient_name==undefined){
		layer.msg("姓名不能为空！");
		return;
	}
	if(patient_sex==null||patient_sex==""||patient_sex==undefined){
		layer.msg("性别不能为空！");
		return;
	}
	if(patient_age==null||patient_age==""||patient_age==undefined){
		layer.msg("年龄不能为空！");
		return;
	}
	if(patient_id==null||patient_id==""||patient_id==undefined){
		//新增
		jQuery.ajax({
			url : rootPath + '/patient/save.shtml',
			data : $("#patient_info").serialize(),
			type : "post",
			dataType : "json",
			success : function(data) {
				if (data.flag == 'success') {
					$("#patient_id").val(data.id);
					$("#patient_number").val(data.patient_number);
					layer.msg("保存成功！");
				} else {
					layer.msg("保存失败！");
				}
			}
		});
	}else{
		//修改
		jQuery.ajax({
			url : rootPath + '/patient/editEntity.shtml',
			data : $("#patient_info").serialize(),
			type : "post",
			success : function(data) {
				data = eval(data);
				if (data == 'success') {
					layer.msg("修改成功！");
				} else {
					layer.msg("修改失败！");
				}
			}
		});
	}

}

function resetfm(){
	$("#patient_id").val("");
}

function selseries(){
	var no = $("select[name='type_no']").val();
	if(no==null||no==""){
		$("#serieshtml").html('该分类下没有任何数据！');
		return;
	}
	jQuery.ajax({
		url : rootPath + '/illness/findseries.shtml',
		data:{no:no},
		type : "get",
		dataType:"json",
		success : function(data) {
			var html="";
			for(var i in data){
				var item = data[i];
				html+="<span style='width: 20%; float: left; height: 30px; line-height: 30px;'><input type='checkbox' name='series' style='margin-right: 10px;' value='"+item.no+"'>"+item.name+"</span>";
			}
			$("#serieshtml").html(html);
		}
	});
}

function getdiagnosis(){
	var type_no = $("input[name='series']:checked").map(function (){ return $(this).val(); }).get().join(",");
	if(type_no==""){
		layer.msg("请选择临床诊断！");
		return;
	}
	var patientId = $("#patient_id").val();
	if(patientId==""){
		layer.msg("请选择/填写患者信息！");
		return;
	}
	url = rootPath + '/illness/findSymptomBySeriesId.shtml?type_no='+type_no;
	pageii = layer.open({
		title : "请选择临床表现",
		type : 2,
		skin: 'layui-layer-rim',
		area : [ "900px", "80%" ],
		content : url,
		btn: ['确定','关闭'],
        yes: function(index,layero){
        	var selvalues = window["layui-layer-iframe" + index].getvalues();
        	$("#loadhtml").load(rootPath + "/case/create.shtml?id=38&patient_id="+patientId+"&symptoms="+encodeURI(encodeURI(selvalues))+"&type_no="+type_no);
        	layer.close(index);
        }        
	});
}